from polls import isErrorId
from . import RedisSDK
from . import json


class GetWxPayFromRedis:

    key = "WxPayRes:"

    redis_sdk = None

    def __init__(self, orderId: str) -> None:
        if isErrorId(orderId):
            raise ValueError("错误的订单 ID ")
        self.key = self.key+orderId
        self.redis_sdk = RedisSDK()

    def get_order(self) -> str:
        '''
        获取订单
        '''
        str_res = self.redis_sdk.get_value(self.key)
        if not str_res:
            return None
        return json.loads(str_res)
